const fs = require('fs');

module.exports = (path) => {
  const basePath = `${process.root}/${path}`;
  const pluginNameList = fs.readdirSync(basePath);
  const plugins = pluginNameList.map(item => {
    const temp = `${basePath}/${item}`;
    const stat = fs.statSync(temp)
    if (stat.isDirectory()) {
      const plugin = require(temp);
      const { name = false, main = false } = plugin;
      if (!name || !main) return;
      console.log(`启用插件: ${name}`);
      return plugin;
    } else {
      console.log('Err:', temp, 'is not a directory')
    }
  }).filter(item => item)
  return plugins;
}